package com.youmans.test;

import javax.imageio.ImageIO;
import java.awt.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.Set;

public class MinioTest2 {
    public static void main(String[] args) throws IOException {
        String str = "asdfasdfasdfyoudfsassdfas4as5.d4f";
        String substring = str.substring(str.lastIndexOf(".") + 1);
        System.out.println(substring);
//        String[] youdfs = str.split("youdfs");
//        for (String youdf : youdfs) {
//            System.out.println(youdf);
//        }


//        String fileName= "C:\\Users\\Administrator\\Desktop\\美女图片_360图片_files\\美女_360图片2_files";
//        File file = new File(fileName);
//        if(!file.exists()){
//            System.err.println("文件夹路径错误");
//        }else{
//            listDir(file);
//        }
    }
    public static Set<String> listDir(File file)throws IOException {
        Set<String> urlList = new HashSet<>() ;
        File[] files = file.listFiles();
        for (File file1 : files) {
            if(file1.isDirectory()){//是文件夹
                File[] files2 = file1.listFiles();
                if(files2 !=null){
                    for (File file3 : files2) {
                        listDir(file3);
                    }
                }

            }else{
                if(isImage(new FileInputStream(file1))){//判断是否为图片
                    urlList.add(file1.getPath());
                    System.out.println(urlList.size());
                    System.err.println(file1.getPath());
                }
            }
            //t01feb5c2038001b19a.jpg
//                System.out.println(file1.getName());
            //C:\Users\Administrator\Desktop\美女图片_360图片_files\美女_360图片2_files\t01feb5c2038001b19a.jpg
//            System.out.println(urlList);
        }
        return urlList ;
    }
    //判断文件是否为图片
    public static boolean isImage(InputStream inputStream) {
        if (inputStream == null) {
            return false;
        }
        Image img;
        try {
            img = ImageIO.read(inputStream);
            return !(img == null || img.getWidth(null) <= 0 || img.getHeight(null) <= 0);
        } catch (Exception e) {
            return false;
        }
    }
}
